<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace addons\order\model;

/**
 * Description of WageWithout
 *
 * @author lsj
 */
class Without extends \web\common\model\BaseModel {

    protected function _initialize() {
        $this->tableName = 'without_order';
    }
    public function getList($pageIndex = -1, $pageSize = -1, $filter = '', $order = 'id asc') {
        $m = new \addons\member\model\MemberAccountModel();
        $sql = 'select a.*,b.username from ' . $this->getTableName() . ' a,'.$m->getTableName().' b where a.user_id=b.id';
        if (!empty($filter))
            $sql .=  ' and '.$filter;
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }


    public function getWithoutList($pageIndex = -1, $pageSize = -1, $filter = '', $fields = 'a.*', $order = 'a.order_index desc') {
        $sql = 'select '.$fields.' from ' . $this->getTableName()  . ' AS  a LEFT JOIN tp_member_account AS b ON a.user_id = b.id LEFT JOIN tp_sys_balance_conf as d on a.coin_type=d.type';
        if (!empty($filter)) {
            $sql = $sql . ' where ' . $filter;
        }
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }

    /**
     * 获取记录总数
     * @param type $filter
     * @return int
     */
    public function getWithoutTotal($filter = '') {
        $sql = 'select count(*) as c from  ' . $this->getTableName()  . ' AS  a LEFT JOIN tp_member_account AS b ON a.user_id = b.id LEFT JOIN tp_sys_balance_conf as d on a.coin_type=d.type';
        if (!empty($filter))
            $sql .= ' where ' . $filter;
        $result = $this->query($sql);

        if (count($result) > 0)
            return intval($result[0]['c']);
        else
            return 0;
    }

    /**
     * 获取记录总数
     * @param type $filter
     * @return int
     */
    public function getWithoutSum($filter = '') {
        $sql = 'select sum(amount) as c from  ' . $this->getTableName()  . ' AS  a LEFT JOIN tp_member_account AS b ON a.user_id = b.id LEFT JOIN tp_sys_balance_conf as d on a.coin_type=d.type';
        if (!empty($filter))
            $sql .= ' where ' . $filter;
        $result = $this->query($sql);

        if (count($result) > 0)
            return intval($result[0]['c']);
        else
            return 0;
    }
    
}